<template>
  <div>
    <div style=" padding: 20px;">
      <a-row :gutter="24">
        <!--        <a-col :span="12" class="someSpace">-->
        <!--          <a-card class="cardShadow" title="绿色工厂试点">-->
        <!--            <a slot="extra" href="#">-->
        <!--              <a-button icon="upload" type="primary" @click="handleOk1()">提交</a-button>-->
        <!--            </a>-->
        <!--            <a-spin :spinning="confirmLoading">-->
        <!--              <a-form :form="form1">-->
        <!--                <a-form-item-->
        <!--                  :labelCol="labelCol"-->
        <!--                  :wrapperCol="wrapperCol"-->
        <!--                  class="verticalCenter" label="数值">-->
        <!--                  <a-input v-decorator="['greenFactoryPilot', {-->
        <!--            rules: [-->
        <!--              {-->
        <!--                required: true,-->
        <!--                message: '绿色工厂试点数量必须为正整数!',-->
        <!--                 pattern: /^(?:0|[1-9]\d*)$/-->
        <!--              },-->
        <!--            ],-->
        <!--            }]" placeholder="请输入绿色工厂试点数量" suffix="家" />-->
        <!--                </a-form-item>-->
        <!--              </a-form>-->
        <!--            </a-spin>-->
        <!--          </a-card>-->
        <!--        </a-col>-->
        <!--        <a-col :span="12" class="someSpace">-->
        <!--          <a-card class="cardShadow" title="碳普惠个人账户">-->
        <!--            <a slot="extra" href="#">-->
        <!--              <a-button icon="upload" type="primary" @click="handleOk2()">提交</a-button>-->
        <!--            </a>-->
        <!--            <a-spin :spinning="confirmLoading">-->
        <!--              <a-form :form="form2">-->
        <!--                <a-form-item-->
        <!--                  :labelCol="labelCol"-->
        <!--                  :wrapperCol="wrapperCol"-->
        <!--                  class="verticalCenter" label="数值">-->
        <!--                  <a-input v-decorator="['carbonPersonalAccount', {-->
        <!--            rules: [-->
        <!--              {-->
        <!--                required: true,-->
        <!--                message: '碳普惠个人账户必须为0或正数!',-->
        <!--                 pattern: /^[0-9]+(\.[0-9]+)?$/-->
        <!--              },-->
        <!--            ],-->
        <!--            }]" placeholder="请输入碳普惠个人账户数量" suffix="g" />-->
        <!--                </a-form-item>-->
        <!--              </a-form>-->
        <!--            </a-spin>-->
        <!--          </a-card>-->
        <!--        </a-col>-->
        <a-col :span="24" class="someSpace">
          <a-card class="cardShadow">
            <a-spin :spinning="confirmLoading">
              <a-row class="cTradeTitle">
                <h2>全国</h2>
              </a-row>
              <a-form :form="form3">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="全国履约企业">
                  <a-input v-decorator="['qyNum', {
            rules: [
              {
                required: true,
                message: '全国履约企业必须必须为正整数!',
                 pattern: /^\d+$/
              },
            ],
            }]" placeholder="请输入全国履约企业数量" suffix="家" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="全国已完成清缴">
                  <a-input v-decorator="['lyl', {
            rules: [
              {
                required: true,
                message: '请输入全国已完成清缴百分比!',
              },
            ],
            }]" placeholder="请输入全国已完成清缴百分比" suffix="%" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="累计交易量">
                  <a-input v-decorator="['ljcjl', {
            rules: [
              {
                required: true,
                message: '请输入累计交易量!',
              },
            ],
            }]" placeholder="请输入累计交易量" suffix="亿吨" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="累计交易额">
                  <a-input v-decorator="['ljcje', {
            rules: [
              {
                required: true,
                message: '请输入累计交易额!',
              },
            ],
            }]" placeholder="请输入累计交易额" suffix="亿元" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="碳单价">
                  <a-input v-decorator="['spj', {
            rules: [
              {
                required: true,
                message: '请输入碳单价!',
              },
            ],
            }]" placeholder="请输入碳单价" suffix="元" />
                </a-form-item>
              </a-form>
              <a-row class="cTradeTitle">
                <h2>全市</h2>
              </a-row>
              <a-form :form="form4">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="全市履约企业">
                  <a-input v-decorator="['qyNum', {
            rules: [
              {
                required: true,
                message: '全市履约企业必须必须为正整数!',
                 pattern: /^\d+$/
              },
            ],
            }]" placeholder="请输入全市履约企业数量" suffix="家" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="全市已完成清缴">
                  <a-input v-decorator="['lyl', {
            rules: [
              {
                required: true,
                message: '请输入全市已完成清缴百分比!',
              },
            ],
            }]" placeholder="请输入全市已完成清缴百分比" suffix="%" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="累计交易量">
                  <a-input v-decorator="['ljcjl', {
            rules: [
              {
                required: true,
                message: '请输入累计交易量!',
              },
            ],
            }]" placeholder="请输入累计交易量" suffix="亿吨" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="累计交易额">
                  <a-input v-decorator="['ljcje', {
            rules: [
              {
                required: true,
                message: '请输入累计交易额!',
              },
            ],
            }]" placeholder="请输入累计交易额" suffix="亿元" />
                </a-form-item>
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  class="verticalCenter" label="碳单价">
                  <a-input v-decorator="['spj', {
            rules: [
              {
                required: true,
                message: '请输入碳单价!',
              },
            ],
            }]" placeholder="请输入碳单价" suffix="元" />
                </a-form-item>
              </a-form>
              <a-button :loading="confirmLoading" class="button" icon="upload" type="primary" @click="handleOk()">提交
              </a-button>
            </a-spin>
          </a-card>
        </a-col>
      </a-row>
    </div>
  </div>
</template>

<script>
// import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, httpAction } from '@api/manage'
import pick from 'lodash.pick'

export default {
  name: 'showDataCards',

  // mixins: [JeecgListMixin],
  data() {
    return {
      model: '',
      confirmLoading: false,
      title: '',
      visible: false,
      form1: this.$form.createForm(this),
      form2: this.$form.createForm(this),
      form3: this.$form.createForm(this),
      form4: this.$form.createForm(this),
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      url: {
        list: '',
        delete: ''
      }
    }
  },
  mounted() {
    getAction('/carbon/carbonDailyTransactionSituation/getData', {})
      .then((res) => {
        if (res.result) {
          console.log(res.result)
          this.model = res.result
          this.$nextTick(() => {
            this.form3.setFieldsValue(pick(
              this.model.cea,
              'qyNum',
              'lyl',
              'ljcjl',
              'ljcje',
              'spj'
            ))
            this.form4.setFieldsValue(pick(
              this.model.sh,
              'qyNum',
              'lyl',
              'ljcjl',
              'ljcje',
              'spj'
            ))
          })
        }
      })
  },
  methods: {
    handleOk() {
      let that = this
      this.form3.validateFields((err, values) => {
        if (!err) {
          let value1 = values
          let httpurl = ''
          let method = ''
          this.confirmLoading = true
          let formData = {}
          formData = Object.assign(this.model.cea, value1)
          httpurl = '/carbon/carbonDailyTransactionSituation/edit'
          method = 'post'
          console.log(httpurl)
          httpAction(httpurl, formData, method).then(res => {
            if (res.success) {
              this.form4.validateFields((err, values) => {
                if (!err) {
                  let value2 = values
                  let httpurl = ''
                  let method = ''
                  this.confirmLoading = true
                  formData = Object.assign(this.model.sh, value2)
                  console.log(formData)
                  httpurl = '/carbon/carbonDailyTransactionSituation/edit'
                  method = 'post'
                  console.log(httpurl)
                  httpAction(httpurl, formData, method).then(res => {
                    if (res.success) {
                      that.$message.success(res.message)
                      that.$emit('refresh')
                    } else {
                      that.$message.error(res.message)
                    }
                  }).finally(() => {
                    that.confirmLoading = false
                  })
                }
              })
            } else {
              that.$message.error(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="stylus" scoped>
.cardShadow {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
}

.verticalCenter {
  //  垂直居中
}

.someSpace {
  margin-bottom: 24px;
}

.cTradeTitle {
  background-color #eeeeee
  padding-left 20px
  padding-top 8px
  margin-bottom 30px
  margin-top 10px
}

.button {
  margin-left: 50%;
  transform: translateX(-50%);
}
</style>